package com.example.sm.mycook;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;

import java.util.List;

/**
 * Created by Administrator on 2016/12/6.
 */
public class PoiSearch_adapter extends BaseAdapter {
    private Context context;
    private List<PoiItem> list;

    public PoiSearch_adapter(Context context, List<PoiItem> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.map_listview_item, parent, false);
            holder.textView = (TextView) convertView.findViewById(R.id.map_listView_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(list.get(position).getTitle() + "\n"
                + list.get(position).getSnippet());

        return convertView;
    }

    class ViewHolder {
        TextView textView;
    }
}
